package May._02;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;


public class Temp {
    public static void main(String[] args) {
        //        "aababcabcdabcde",获取字符串中每一个字母出现的次数要求结果:a(5)b(4)c(3)d(2)e(1)

        String str = "aababcabcdabcde";
        Map<Character, Integer> map = new HashMap<>();
        // 遍历每个字符
        for (int i = 0; i < str.length(); i++) {
            char c = str.charAt(i);
            Integer count = map.get(c);
            if (count == null) {
                count = 0;
            }
            map.put(c, count + 1);
        }

        StringBuffer buffer = new StringBuffer();
        Set<Character> characters = map.keySet();
        for (Character character : characters) {
            buffer.append(character);
            buffer.append("(" + map.get(character) + ")");
        }
        System.out.println(buffer.toString());
    }
}
